package com.eagle.roomsearch.controller.springMvcStudyDemo;

import com.eagle.roomsearch.mapper.HolidayMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/*
全部满足下面的要求
*1.浏览器限制  2.XHR请求 3.跨域
解决思路：
    浏览器-->>XHR(jsonp)-->>跨域（1.被调用方（支持跨域）2.调用方（隐藏跨域）通过代理）
 */
@RestController
@RequestMapping("/test")
public class TestController {

    @Autowired
    private HolidayMapper holidayMapper;

    @GetMapping("/get1")
    private ResultBean get1(){
        System.out.println("TestController.get1()");

        return new ResultBean(holidayMapper.selectAll().toString());
    }
    @PostMapping("/postJson")
    public ResultBean postJson(@RequestBody User user) {
        System.out.println("TestController.postJson()");

        return new ResultBean("postJson " + user.getName());
    }

    @GetMapping("/getCookie")
    public ResultBean getCookie(@CookieValue(value = "cookie1") String cookie1) {
        System.out.println("TestController.getCookie()");
        return new ResultBean("getCookie " + cookie1);
    }

    @GetMapping("/getHeader")
    public ResultBean getHeader(@RequestHeader("x-header1") String header1,
                                @RequestHeader("x-header2") String header2) {
        System.out.println("TestController.getHeader()");

        return new ResultBean("getHeader " + header1 + " " + header2);
    }
}
